(* $Id: demangle.ml 218 2009-03-06 09:40:54Z yann.regisgianas $ *)

(* Pangolin, a functional programming language for correct programs.
   Copyright (C) 2007, Yann Régis-Gianas, François Pottier.
   Contact: yann.regisgianas@gmail.com

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. *)

let demangle_char = function
  | '<' -> "lt_"
  | '>' -> "gt_"
  | '{' -> "lbrace_"
  | '}' -> "rbrace_"
  | '*' -> "times_"
  | '&' -> "uppersand_"
  | '%' -> "percent_"
  | '?' -> "qmark_"
  | '^' -> "hat_"
  | '\\' -> "backslash_"
  | '@' -> "at_"
  | '#' -> "sharp_"
  | '+' -> "plus_"
  | '-' -> "minus_"
  | '|' -> "" (* used as a separator in internal identifier. *)
  | '\'' -> "prime_"
  | '=' -> "equal_"
  | c -> String.make 1 c

let rec str s =
  if s.[0] = '_' then str ("wildcard" ^ s) 
  else 
    let ret = Buffer.create 13 in
      for i = 0 to String.length s - 1 do
	Buffer.add_string ret (demangle_char s.[i])
      done;
      Buffer.contents ret
    
